home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2690 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.5 KB

  1. Path: colossus.holonet.net!russell
  2. From: russell@news.mdli.com (Russell Blackadar)
  3. Newsgroups: comp.object,comp.lang.c++,comp.ai.alife,sci.comp-aided
  4. Subject: Re: [Q] Growing Objects
  5. Followup-To: comp.object,comp.lang.c++,comp.ai.alife,sci.comp-aided
  6. Date: 19 Jan 1996 04:07:04 GMT
  7. Organization: HoloNet National Internet Access System: 510-704-1058/modem
  8. Message-ID: <4dn5d8$lor@colossus.holonet.net>
  9. References: <30FE8297.41C6@bme.jhu.edu>
  10. NNTP-Posting-Host: jubal.mdli.com
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Harold Bien (hbien@bme.jhu.edu) wrote:
  14.  [much deleted]
  15. :      The class Cell has a function Run() which takes no arguments but 
  16. : calls another function through a pointer to a member function.  Then, 
  17. : when that member function runs, it updates a variable 'age' and checks
  18. : to see if it is mature.  If so, then it will change the pointer to point
  19. : to another function.  Here's what it will look like:
  20.  
  21. That idea seems fine to me.  *The* classic use of member-function 
  22. pointers is to dispatch to different methods depending on some state
  23. of the object (e.g. "age" in your case).
  24.  
  25. [code deleted, except...]
  26.  
  27. :  RunFunc=Run_PreMature; /* Point RunFunc to PreMature() function */
  28.            ^^^^^^^^^^^^^
  29. and
  30.  
  31. :  if (age>=4) RunFunc=Run_PostMature;    ...
  32.                        ^^^^^^^^^^^^^^
  33.  
  34. You should put a "&" in front of these, to comply with the standard.
  35. Some compilers let you get away without it, but who knows if you'll
  36. always use the same compiler.
  37.  
  38. BTW, you might find // comments to your liking, in the above.
  39. --
  40. Russell Blackadar,   russell@mdli.com
  41.